<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>零件明细查看</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <input id="query-proCode" th:value="${proCodeId}" type="hidden" name="proCode"
                                       class="form-control">
<!--                                <input id="query-prodChange" th:value="${prodChange}" type="hidden" name="prodChange"-->
<!--                                       class="prodChange">-->
                                <input id="query-specialId" th:value="${special}" type="hidden" name="special"
                                       class="form-control">
<!--                                <input id="query-deptName" th:value="${deptName}" type="hidden" name="deptName"-->
<!--                                       class="form-id">-->
                                <input id="query-partId" th:value="${part}" type="hidden" name="part"
                                       class="form-control">
                                <input id="query-recStatus" th:value="${recStatus}" type="hidden" name="recStatus"
                                       class="form-control">
                                <div class="form-group">
                                    <label for="query-drawNo">零件图号</label>
                                    <input id="query-drawNo" type="text" name="drawNo" class="form-control"
                                           placeholder="请输零件图号">
                                </div>
                                <div class="form-group">
                                    <label for="query-drawName">零件图名</label>
                                    <input id="query-drawName" type="text" name="drawName" class="form-control"
                                           placeholder="请输零件图名">
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                        <div class="row" style="margin-top: 30px">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode1" type="text" class="form-control"
                                           style="border: none;width: 100Px;background-color: white"
                                           th:value="${proCodeId}" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" th:value="${proName}" type="text" name="proName" class="form-control"
                                           style="border: none;width: 200px;background-color: white"  readonly>
                                </div>
                                <div class="form-group">
                                    <label for="query-proNum">项目数量</label>
                                    <input id="query-proNum" th:value="${proNum}" type="text" name="proNum" class="form-control"
                                           style="border: none;width: 100px;background-color: white"   readonly>
                                </div>
                                <div class="form-group">
                                    <label for="query-special">专业</label>
                                    <input id="query-special" type="text"  class="form-control"
                                           style="border: none;width: 80px;background-color: white"
                                           th:value="${special}" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部分</label>
                                    <input id="query-part" type="text"  class="form-control"
                                           style="border: none;width: 100px;background-color: white"
                                           th:value="${part}" readonly>
                                </div>
                                <div class="form-group">
                                    <label for="query-part">工艺卡数量</label>
                                    <input id="query-card-num" type="text" class="form-control"
                                           style="border: none;width: 100px;background-color: white" readonly>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;

    $(function () {
        /** 子表 */
        table = js.table.init({
            id: "bootstrap-table",
            queryForm: "queryForm",
            url: ctx + "tecard/selectMakeDetail",
            showExport: false,
            onLoadSuccess:function (data){
                /**
                 * 获取工艺卡数量
                 */
                js.post({
                    url: ctx + "tecard/getCardNum",
                    data: $("#queryForm").serialize(),
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            $("#query-card-num").val(result.data);
                        } else {
                            js.modal.warning(result.msg);
                        }
                    }
                })
            },
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "零件图号", field: 'drawNo',
                    formatter: function (value,row){
                        return value;
                    }
                },
                {title: "零件名称", field: 'drawName'},
                {title: "零件数量", field: 'drawNum'},
                {title: "制作件类型", field: 'makeType'},
                {title: "材质", field: 'quality'},
                {title: "规格", field: 'specification'},
                {title: "重量（KG）", field: 'weight'},
                {title: "接收人", field: 'recName'},
                {title: "接收时间", field: 'recTime'},
                {title: "工艺卡状态", field: 'recName',
                    formatter:function (value, row) {
                        if(row.recName == null && row.mayChange == 1 && row.recStatus == 0){
                            return '<span class="label label-warning">变更待接收</span>';
                        }else if(row.recName == null && row.mayChange == 1 && row.status == 5){
                            return '<span class="badge label-inverse">变更未接收</span>';
                        }else if (row.recName == null && row.mayChange == 1 && row.status != 5){
                            return '<span class="label label-info">工艺卡变更中</span>';
                        } else {
                            return '<span class="label label-success">正常</span>';
                        }
                    }
                },
                {
                    title: "操作",
                    // width: '160px',
                    formatter: function (value, row) {
                        let actions = [];
                        if(row.isNeedCard==1 && row.recStatus == 1){
                            actions.push('<a class="btn btn-info btn-xs" target="_blank" href="' + ctx + 'task/productionListView/selectCard/' + row.sheetId + '"> 查看</a>');
                        } else if(row.recStatus == 0){
                            actions.push('<a class="btn btn-info btn-xs" target="_blank" href="' + ctx + 'tecard/full/' + row.id + '"> 查看</a>');
                        }
                        if(row.recStatus == 1 && hasP('est:cardList:del')){
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="delCard('+ row.id +')">删除</a>')
                        }
                        return actions.join('');
                    }
                }
            ]
        });
    });

    /**
     * 删除工艺卡
     */
    function delCard(id) {
        js.modal.confirm("确认是否删除工艺卡，删除后将不能恢复当前工艺卡信息？",function () {
            js.post({
                url:ctx + "tecard/del",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

</script>
</body>
</html>
